import type * as PostCSS from "postcss";
import type { Configuration } from "webpack";
import type WebpackDevServer from "webpack-dev-server";
export interface EnvType {
  WEBPACK_BUILD?: boolean;
  WEBPACK_WATCH?: boolean;
  WEBPACK_SERVE?: boolean;
  NODE_ENV?: string;
}

export declare interface CSSModulesOptions {
  getJSON?: (
    cssFileName: string,
    json: Record<string, string>,
    outputFileName: string
  ) => void;
  scopeBehaviour?: "global" | "local";
  globalModulePaths?: RegExp[];
  generateScopedName?:
    | string
    | ((name: string, filename: string, css: string) => string);
  hashPrefix?: string;
  localsConvention?:
    | "camelCase"
    | "camelCaseOnly"
    | "dashes"
    | "dashesOnly"
    | null;
}

export declare interface CSSOptions {
  modules?: CSSModulesOptions | false;
  preprocessorOptions?: Record<string, any>;
  postcss?:
    | string
    | (PostCSS.ProcessOptions & {
        plugins?: PostCSS.Plugin[];
      });
  devSourcemap?: boolean;
}

export interface WebpackConfigType extends Configuration {
  devServer?: WebpackDevServer.Configuration;
}

export interface UserConfig extends WebpackConfigType {
  env?: EnvType | { [key: string]: any };
  css?: CSSOptions;
}

export declare interface ConfigEnv {
  command: "build" | "serve";
  mode: string;
}

export declare type UserConfigFn = (
  env: ConfigEnv
) => UserConfig | Promise<UserConfig>;

export declare type UserConfigExport =
  | UserConfig
  | Promise<UserConfig>
  | UserConfigFn;
